﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace Maticsoft.DAL
{
	/// <summary>
	/// 数据访问类:expertConfirm
	/// </summary>
	public partial class expertConfirm
	{
		public expertConfirm()
		{}
        #region  BasicMethod

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return DbHelperSQL.GetMaxID("expertConfirmId", "expertConfirm");
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int expertConfirmId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from expertConfirm");
            strSql.Append(" where expertConfirmId=@expertConfirmId");
            SqlParameter[] parameters = {
					new SqlParameter("@expertConfirmId", SqlDbType.Int,4)
			};
            parameters[0].Value = expertConfirmId;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Maticsoft.Model.expertConfirm model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into expertConfirm(");
            strSql.Append("tenderNum,sExpertrName,jExpertName,projectname,superviseId,superviseName,randomId,randomName,time,status,expertInfoId)");
            strSql.Append(" values (");
            strSql.Append("@tenderNum,@sExpertrName,@jExpertName,@projectname,@superviseId,@superviseName,@randomId,@randomName,@time,@status,@expertInfoId)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@tenderNum", SqlDbType.VarChar,50),
					new SqlParameter("@sExpertrName", SqlDbType.VarChar,-1),
					new SqlParameter("@jExpertName", SqlDbType.VarChar,-1),
					new SqlParameter("@projectname", SqlDbType.NVarChar,100),
					new SqlParameter("@superviseId", SqlDbType.Int,4),
					new SqlParameter("@superviseName", SqlDbType.NVarChar,20),
					new SqlParameter("@randomId", SqlDbType.Int,4),
					new SqlParameter("@randomName", SqlDbType.NVarChar,20),
					new SqlParameter("@time", SqlDbType.DateTime),
					new SqlParameter("@status", SqlDbType.Int,4),
					new SqlParameter("@expertInfoId", SqlDbType.Int,4)};
            parameters[0].Value = model.tenderNum;
            parameters[1].Value = model.sExpertrName;
            parameters[2].Value = model.jExpertName;
            parameters[3].Value = model.projectname;
            parameters[4].Value = model.superviseId;
            parameters[5].Value = model.superviseName;
            parameters[6].Value = model.randomId;
            parameters[7].Value = model.randomName;
            parameters[8].Value = model.time;
            parameters[9].Value = model.status;
            parameters[10].Value = model.expertInfoId;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Maticsoft.Model.expertConfirm model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update expertConfirm set ");
            strSql.Append("tenderNum=@tenderNum,");
            strSql.Append("sExpertrName=@sExpertrName,");
            strSql.Append("jExpertName=@jExpertName,");
            strSql.Append("projectname=@projectname,");
            strSql.Append("superviseId=@superviseId,");
            strSql.Append("superviseName=@superviseName,");
            strSql.Append("randomId=@randomId,");
            strSql.Append("randomName=@randomName,");
            strSql.Append("time=@time,");
            strSql.Append("status=@status,");
            strSql.Append("expertInfoId=@expertInfoId");
            strSql.Append(" where expertConfirmId=@expertConfirmId");
            SqlParameter[] parameters = {
					new SqlParameter("@tenderNum", SqlDbType.VarChar,50),
					new SqlParameter("@sExpertrName", SqlDbType.VarChar,-1),
					new SqlParameter("@jExpertName", SqlDbType.VarChar,-1),
					new SqlParameter("@projectname", SqlDbType.NVarChar,100),
					new SqlParameter("@superviseId", SqlDbType.Int,4),
					new SqlParameter("@superviseName", SqlDbType.NVarChar,20),
					new SqlParameter("@randomId", SqlDbType.Int,4),
					new SqlParameter("@randomName", SqlDbType.NVarChar,20),
					new SqlParameter("@time", SqlDbType.DateTime),
					new SqlParameter("@status", SqlDbType.Int,4),
					new SqlParameter("@expertInfoId", SqlDbType.Int,4),
					new SqlParameter("@expertConfirmId", SqlDbType.Int,4)};
            parameters[0].Value = model.tenderNum;
            parameters[1].Value = model.sExpertrName;
            parameters[2].Value = model.jExpertName;
            parameters[3].Value = model.projectname;
            parameters[4].Value = model.superviseId;
            parameters[5].Value = model.superviseName;
            parameters[6].Value = model.randomId;
            parameters[7].Value = model.randomName;
            parameters[8].Value = model.time;
            parameters[9].Value = model.status;
            parameters[10].Value = model.expertInfoId;
            parameters[11].Value = model.expertConfirmId;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int expertConfirmId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from expertConfirm ");
            strSql.Append(" where expertConfirmId=@expertConfirmId");
            SqlParameter[] parameters = {
					new SqlParameter("@expertConfirmId", SqlDbType.Int,4)
			};
            parameters[0].Value = expertConfirmId;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string expertConfirmIdlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from expertConfirm ");
            strSql.Append(" where expertConfirmId in (" + expertConfirmIdlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Maticsoft.Model.expertConfirm GetModel(int expertConfirmId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 expertConfirmId,tenderNum,sExpertrName,jExpertName,projectname,superviseId,superviseName,randomId,randomName,time,status,expertInfoId from expertConfirm ");
            strSql.Append(" where expertConfirmId=@expertConfirmId");
            SqlParameter[] parameters = {
					new SqlParameter("@expertConfirmId", SqlDbType.Int,4)
			};
            parameters[0].Value = expertConfirmId;

            Maticsoft.Model.expertConfirm model = new Maticsoft.Model.expertConfirm();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Maticsoft.Model.expertConfirm DataRowToModel(DataRow row)
        {
            Maticsoft.Model.expertConfirm model = new Maticsoft.Model.expertConfirm();
            if (row != null)
            {
                if (row["expertConfirmId"] != null && row["expertConfirmId"].ToString() != "")
                {
                    model.expertConfirmId = int.Parse(row["expertConfirmId"].ToString());
                }
                if (row["tenderNum"] != null)
                {
                    model.tenderNum = row["tenderNum"].ToString();
                }
                if (row["sExpertrName"] != null)
                {
                    model.sExpertrName = row["sExpertrName"].ToString();
                }
                if (row["jExpertName"] != null)
                {
                    model.jExpertName = row["jExpertName"].ToString();
                }
                if (row["projectname"] != null)
                {
                    model.projectname = row["projectname"].ToString();
                }
                if (row["superviseId"] != null && row["superviseId"].ToString() != "")
                {
                    model.superviseId = int.Parse(row["superviseId"].ToString());
                }
                if (row["superviseName"] != null)
                {
                    model.superviseName = row["superviseName"].ToString();
                }
                if (row["randomId"] != null && row["randomId"].ToString() != "")
                {
                    model.randomId = int.Parse(row["randomId"].ToString());
                }
                if (row["randomName"] != null)
                {
                    model.randomName = row["randomName"].ToString();
                }
                if (row["time"] != null && row["time"].ToString() != "")
                {
                    model.time = DateTime.Parse(row["time"].ToString());
                }
                if (row["status"] != null && row["status"].ToString() != "")
                {
                    model.status = int.Parse(row["status"].ToString());
                }
                if (row["expertInfoId"] != null && row["expertInfoId"].ToString() != "")
                {
                    model.expertInfoId = int.Parse(row["expertInfoId"].ToString());
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM VExpertConfirm ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by  time  desc ");
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" expertConfirmId,tenderNum,sExpertrName,jExpertName,projectname,superviseId,superviseName,randomId,randomName,time,status,expertInfoId ");
            strSql.Append(" FROM expertConfirm ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM expertConfirm ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.expertConfirmId desc");
            }
            strSql.Append(")AS Row, T.*  from expertConfirm T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "expertConfirm";
            parameters[1].Value = "expertConfirmId";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod
		#region  ExtensionMethod
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteListByWhere(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from expertConfirm ");

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

       /// <summary>
       ///  更改审核状态
       /// </summary>
       /// <param name="strWhere"></param>
        /// <param name="status">0、正在审核，1、审核通过，2、审核不通过,3、此专家无效重新抽选</param>
       /// <returns></returns>
        public bool UpdateStatus(string strWhere,int status)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update expertConfirm set ");
            strSql.Append("status=" + status );
            strSql.Append(" where " + strWhere + ";");

            strSql.Append("  ");
           

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
       
		#endregion  ExtensionMethod
	}
}

